package org.mxp.demo7;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import org.mxp.utils.RabbitMQUtils;

public class SendObj {
    public static void main(String[] args) throws Exception {
        // 交换机名称
        String EXCHANGE_NAME = "direct_logs";
        // 获取信道
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换机，第一个参数为交换机名称，第二个参数为交换机类型
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        // 分别给不同的routingKey发送不同的消息
        channel.basicPublish(EXCHANGE_NAME, "info", null, "info日志".getBytes());
        channel.basicPublish(EXCHANGE_NAME, "warning", null, "warning日志".getBytes());
        channel.basicPublish(EXCHANGE_NAME, "error", null, "error日志".getBytes());
        System.out.println("消息发送完毕");
    }
}
